//
//  XinLiCePingTCell.m
//  students
//
//  Created by 任辰东 on 2024/2/26.
//

#import "XinLiCePingTCell.h"
#import "NSString+Timestamp.h"

@interface XinLiCePingTCell ()

@property (nonatomic, strong) UIView *containerView;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *createrLabel;
@property (nonatomic, strong) UILabel *numLabel;

//@property (nonatomic, strong) UILabel *resultLabel;
@property (nonatomic, strong) UIView *line;
@property (nonatomic, strong) UIButton *functionBtn;
@end

@implementation XinLiCePingTCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)configCellWithModel:(XinLiCePingListModel *)model
{
    self.timeLabel.text = [model.create_time dateStringWithFormat:@"yyyy-MM-dd HH:mm"];
    self.titleLabel.text = model.name;
    self.createrLabel.text = [NSString stringWithFormat:@"创建人：%@",model.faburen];
    self.numLabel.text = [NSString stringWithFormat:@"%@人测评过",IsEmpty(model.num)?@"0":model.num];
    
    if (model.is_answer.boolValue) {
        
        [self.functionBtn setTitle:@"查看详情" forState:UIControlStateNormal];
        [self.functionBtn setBackgroundColor:UIColorFromHex(0xffffff)];
        [self.functionBtn setTitleColor:UIColorFromHex(0x000000) forState:UIControlStateNormal];;
        self.functionBtn.layer.borderColor = UIColorFromHex(0xdcdcdc).CGColor;
        
    } else {
      
        [self.functionBtn setTitle:@"参与测评" forState:UIControlStateNormal];
        [self.functionBtn setBackgroundColor:UIColorFromHex(kColorMain)];
        [self.functionBtn setTitleColor:UIColorFromHex(0xffffff) forState:UIControlStateNormal];;
        self.functionBtn.layer.borderColor = UIColorFromHex(kColorMain).CGColor;
    }
    
}

- (void)functionBtnAction
{
    if (self.functionBtnClicked) {
        self.functionBtnClicked();
    }
}

-(void)setupViews
{
    self.contentView.backgroundColor = UIColorFromHex(kColorBG);
    [self.contentView addSubview:self.containerView];
    [self.containerView addSubview:self.timeLabel];
    [self.containerView addSubview:self.titleLabel];
    [self.containerView addSubview:self.createrLabel];
    [self.containerView addSubview:self.numLabel];
//    [self.containerView addSubview:self.resultLabel];
    [self.containerView addSubview:self.line];
    [self.containerView addSubview:self.functionBtn];

    [self.functionBtn addTarget:self action:@selector(functionBtnAction) forControlEvents:UIControlEventTouchUpInside];
}

-(void)setupLayout
{
    [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.left.right.equalTo(self.contentView);
        make.bottom.equalTo(self.contentView).offset(-10);
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.containerView).offset(15);
        make.left.equalTo(self.containerView).offset(15);
        make.right.equalTo(self.containerView).offset(-15);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.timeLabel.mas_bottom).offset(15);
        make.left.equalTo(self.containerView).offset(15);
        make.right.equalTo(self.containerView).offset(-15);
    }];
    
    [self.createrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.titleLabel.mas_bottom).offset(15);
        make.left.equalTo(self.containerView).offset(15);
    }];
    
    [self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.titleLabel.mas_bottom).offset(15);
        make.left.equalTo(self.createrLabel.mas_right).offset(5);
        make.right.equalTo(self.containerView).offset(-15);
    }];
    
    
//    [self.resultLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        
//        make.top.equalTo(self.titleLabel.mas_bottom).offset(15);
//        make.left.equalTo(self.containerView).offset(15);
//        make.right.equalTo(self.containerView).offset(-15);
//    }];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.createrLabel.mas_bottom).offset(15);
        make.left.equalTo(self.containerView).offset(15);
        make.right.equalTo(self.containerView).offset(-15);
        make.height.mas_equalTo(kOnePixel);
    }];
    
    [self.functionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.line.mas_bottom).offset(15);
        make.right.equalTo(self.containerView).offset(-15);
        make.bottom.equalTo(self.containerView).offset(-15);
        make.height.mas_equalTo(25);
        make.width.mas_greaterThanOrEqualTo(85);
    }];
}

#pragma mark -- lazyload

-(UIView *)containerView
{
    if (!_containerView) {
        _containerView = [UIView new];
        _containerView.backgroundColor = UIColorFromHex(kColorWhite);
    }
    return _containerView;
}

-(UILabel *)timeLabel
{
    if (!_timeLabel) {
        _timeLabel = [UILabel new];
        _timeLabel.text = @"时间";
        _timeLabel.textColor = UIColorFromHex(kColorPlaceholder);
        _timeLabel.numberOfLines = 0;
        _timeLabel.font = UIFontSize(13);
    }
    return _timeLabel;
}

-(UILabel *)createrLabel
{
    if (!_createrLabel) {
        _createrLabel = [UILabel new];
        _createrLabel.text = @"创建人";
        _createrLabel.textColor = UIColorFromHex(kColorSubTitle);
        _createrLabel.numberOfLines = 0;
        _createrLabel.font = UIFontSize(13);
    }
    return _createrLabel;
}

-(UILabel *)numLabel
{
    if (!_numLabel) {
        _numLabel = [UILabel new];
        _numLabel.text = @"测评人数";
        _numLabel.textColor = UIColorFromHex(kColorSubTitle);
        _numLabel.font = UIFontSize(13);
        _numLabel.textAlignment = NSTextAlignmentRight;
    }
    return _numLabel;
}

-(UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.text = @"标题";
        _titleLabel.textColor = UIColorFromHex(0x000000);
        _titleLabel.font = UIFontSize(15);
    }
    return _titleLabel;
}

//-(UILabel *)resultLabel
//{
//    if (!_resultLabel) {
//        _resultLabel = [UILabel new];
//        _resultLabel.text = @"测评结果";
//        _resultLabel.textColor = UIColorFromHex(kColorSubTitle);
//        _resultLabel.font = UIFontSize(13);
//    }
//    return _resultLabel;
//}

-(UIView *)line
{
    if (!_line) {
        
        _line = [UIView new];
        _line.backgroundColor = UIColorFromHex(kColorLine);
    }
    return _line;
}

-(UIButton *)functionBtn
{
    if (!_functionBtn) {
        _functionBtn = [UIButton new];
        [_functionBtn setTitle:@"参与测评" forState:UIControlStateNormal];
        [_functionBtn setTitleColor:UIColorFromHex(kColorMain) forState:UIControlStateNormal];;
        _functionBtn.titleLabel.font = UIFontSize(15);
        _functionBtn.layer.borderWidth = 1;
        _functionBtn.layer.borderColor = UIColorFromHex(kColorMain).CGColor;
        _functionBtn.layer.cornerRadius = 12.5;
        _functionBtn.layer.masksToBounds = YES;
    }
    return _functionBtn;
}



@end
